import actionTypes from '../actions/actionTypes'

const initState = {
    graph: {
        nodes: [
            {
                id: 1,
                name: '1',
                group: '国企',
                fx: 0,
                fy: 0
            }, 
            {
                id: 2, 
                name: '2',
                group: '私企',
                fx: 50,
                fy: 0,
                isBreakPoint: true
            }, 
            {
                id: 3,
                name: '3',
                group: '组合',
                isBreakPoint: true,
                isBlockPoint: true
            }, 
            {
                id: 4,
                name: '物资3',
                group: '物资',
                isBlockPoint: true
            }
        ],
        links: [
            {
                source: 1, 
                target: 2
            }, 
            {
                source: 3,
                target: 4
            }, 
            {
                source: 3, 
                target: 1
            }
        ]
    }, 
    isLoading: false
}

export default (state = initState, action) => {
    switch(action.type) {
        case actionTypes.START_FETCH_ROBUSTNESS_GRAPH:
            return {
                ...state,
                isLoading: true
            }
        case actionTypes.FETCH_ROBUSTNESS_GRAPH_SUCCESS:
            return {
                ...state,
                graph: action.payload.graph,
                isLoading: false
            }
        case actionTypes.FETCH_ROBUSTNESS_GRAPH_FAILED:
            return {
                ...state,
                isLoading: false
            }
        default:
            return state
    }
}